package com.yhb.service.impl;

import com.yhb.channel.provider.IUtilProvider;
import com.yhb.dao.LogMapper;
import com.yhb.service.UtilService;
import com.yhb.utils.Constants;
import com.yhb.utils.DateUtils;
import me.edzh.spring.bootstrap.common.GlobalPropertiesConfigurer;
import org.apache.log4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class UtilServiceImpl implements UtilService, IUtilProvider {

    @Autowired
    private LogMapper logMapper;

    @Async
    @Override
    public void log(String type, String content) {
        String userId = null;
        Object obj = MDC.get(Constants.LOG_USER_ID);
        if (obj != null) {
            userId = obj.toString();
        }
        logMapper.insertLog(DateUtils.getCurrentDateString(), userId, type, content);
    }

    @Override
    public String getProperty(String key) {
        return GlobalPropertiesConfigurer.getProperty(key);
    }

    @Override
    public void savePayChannelFlow(String prefix, String flow) {
        log(prefix, flow);
    }
}
